<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
</head>
<body>
<script th:inline="javascript">
	// 如果不允许为空，则在此需取消掉，因为在submit事件前，livevalidation先作了检测
	if (typeof(f_[(${fieldName})])!="undefined") {
		f_[(${fieldName})].formObj.removeField(f_[(${fieldName})]);
	}

	function myEditor_paste(type, data, fieldName) {
		if (o("webedit")) {
			var imgPath = o("webedit").SavePasteToFile();
			if (imgPath!="") {
				UE.getEditor(fieldName).focus();
				UE.getEditor(fieldName).execCommand('inserthtml', "<img src='" + imgPath + "' />");
			}
		}
	}

	// 使用过的Ueditor ID被删除后，再次用之前的ID创建ueditor实例会失败
	// 所以在vue中需先销毁再创建，否则只能显示一次
	if (UE.isEditorExist("[(${fieldName})]")) {
		try {
			UE.delEditor("[(${fieldName})]");
		} catch (e) {
			console.error(e);
		}
	}

	function initUEditor(fieldName, flowId, id, formCode) {
		var uEditor = UE.getEditor(fieldName, {
			//allowDivTransToP: false,//阻止转换div 为p
			toolleipi:true,//是否显示，设计器的 toolbars
			textarea: 'htmlcode',
			enableAutoSave: false,
			toolbars: [[
				'fullscreen', 'source', '|', 'undo', 'redo', '|',
				'bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', 'autotypeset', 'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'selectall', 'cleardoc', '|',
				'rowspacingtop', 'rowspacingbottom', 'lineheight', '|',
				'paragraph', 'fontfamily', 'fontsize', '|',
				'directionalityltr', 'directionalityrtl', 'indent', '|',
				'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', '|', 'touppercase', 'tolowercase', '|',
				'link', 'unlink', 'anchor', '|', 'imagenone', 'imageleft', 'imageright', 'imagecenter', '|',
				'simpleupload', 'insertimage', 'insertvideo', 'emotion', 'map', 'insertframe', 'insertcode', 'pagebreak', 'template', '|',
				'horizontal', 'date', /*'time'*/, 'spechars', '|',
				'inserttable', 'deletetable', 'insertparagraphbeforetable', 'insertrow', 'deleterow', 'insertcol', 'deletecol', 'mergecells', 'mergeright', 'mergedown', 'splittocells', 'splittorows', 'splittocols', '|',
				'print', 'preview', 'searchreplace', 'help'
			]],
			//focus时自动清空初始化时的内容
			//autoClearinitialContent:true,
			//关闭字数统计
			wordCount:false,
			//关闭elementPath
			elementPathEnabled:false,
			//默认的编辑区域高度
			initialFrameHeight:300,
			initialFrameWidth:'100%',
			disabledTableInTable:false
			///,iframeCssUrl:"css/bootstrap/css/bootstrap.css" //引入自身 css使编辑器兼容你网站css
			//更多其他参数，请参考ueditor.config.js中的配置项
		});
		console.log('initUEditor uEditor.key', uEditor.key);

		uEditor.addListener('beforepaste', myEditor_paste, fieldName);
	}

	initUEditor('[(${fieldName})]', [(${flowId})], [(${id})], '[(${formCode})]');

	function initUeditorActionUrl(flowId, id, formCode) {
		UE.Editor.prototype._bkGetActionUrl = UE.Editor.prototype.getActionUrl;
		UE.Editor.prototype.getActionUrl = function(action) {
			if (action == 'uploadimage' || action == 'uploadscrawl') {
				return '[(${rootPath})]/ueditor/UploadFile?op=UEditorCtl&flowId=' + flowId + '&id=' + id + '&formCode=' + formCode;
			} else if (action == 'uploadvideo') {
				return '[(${rootPath})]/ueditor/UploadFile?op=UEditorCtl&flowId=' + flowId + '&id=' + id + '&formCode=' + formCode;
			} else {
				return this._bkGetActionUrl.call(this, action);
			}
		}
	}

	if (typeof isUeditorActionUrlInited == 'undefined') {
		// console.log('isUeditorActionUrlInited', isUeditorActionUrlInited);
		// 此处不能初始化两次，否则会导致 _bkGetActionUrl 的地址在第二次初始化时，成为了其本身，当调用getActionUrl时陷入循环，致堆栈溢出
		isUeditorActionUrlInited = true;
		window.setTimeout("initUeditorActionUrl([(${flowId})], [(${id})], '[(${formCode})]')", 0);
	}
</script>
</body>
</html>